QuickLook
The QuickLook API in the Scripting app provides a simple way to preview text, images, or files within your scripts. This is a wrapper around iOS QuickLook capabilities, allowing you to quickly display previews for a wide range of content types.
Each method returns a promise that resolves when the QuickLook view is dismissed, enabling you to chain actions or handle post-preview logic easily.
API Reference
QuickLook.previewText(text: string): Promise<void>
Displays a preview of a text string.
Parameters
text(string): The text content to display in the preview.fullscreen(boolean?): Whether preview in a fullscreen mode. Defaults to false.
Returns
- A
Promise<void>: Resolves after the preview is dismissed.
Example
QuickLook.previewImage(image: UIImage): Promise<void>
Displays a preview of an image.
Parameters
image(UIImage): The image to display in the preview.fullscreen(boolean?): Whether preview in a fullscreen mode. Defaults to false.
Returns
- A
Promise<void>: Resolves after the preview is dismissed.
Example
QuickLook.previewURLs(urls: string[]): Promise<void>
Displays a preview of one or more files located at the given file URL strings.
Parameters
urls(string[]): An array of file URL strings. Each string should point to a valid file path or remote file that can be previewed by QuickLook.fullscreen(boolean?): Whether preview in a fullscreen mode. Defaults to false.
Returns
- A
Promise<void>: Resolves after the preview is dismissed.
Example
Usage Notes
- UI Blocking: These methods present a modal QuickLook view. Execution of subsequent code (after
await) will pause until the user dismisses the preview. - Error Handling: Use
try...catchto handle errors such as invalid file paths or unsupported content types. - Supported File Types: The supported file types depend on iOS QuickLook capabilities, which include common file types like PDFs, images, text files, and more.
Example Use Case
Previewing Text, Images, and Files Sequentially
With this API, you can integrate QuickLook previews seamlessly into your scripts, enhancing the user experience with minimal effort.
